package org.openkoala.demo.application.impl;

import java.util.List;
import java.util.Set;
import javax.inject.Named;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import org.openkoala.demo.application.UserApplication;
import org.openkoala.demo.core.domain.User;

@Named
public class UserApplicationImpl implements UserApplication {

	@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
	public User getUser(Long id) {
		return User.get(User.class, id);
	}
	
	public void saveUser(User user) {
		user.save();
	}
	
	public void updateUser(User user) {
		user .save();
	}
	
	public void removeUser(User user) {
		if(user != null){
			user.remove();
		}
	}
	
	public void removeUsers(Set<User> users) {
		for (User user : users) {
			user.remove();
		}
	}
	
	@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
	public List<User> findAllUser() {
		return User.findAll(User.class);
	}
	
}
